﻿@{
    ViewBag.Title = "StaffIndex";
    Layout = "~/Views/Users/Index.cshtml";
}
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<link href="~/css/bootstrap.css" rel="stylesheet" />

<script src="~/js/jquery.min.js"></script>
<script src="~/js/bootstrap.min.js"></script>
<script>
    $(function () {
        $.ajax({
            type: "post",
            url: "/Staff/StaffIndexs",
            success: function (obj)
            {
                $("#tds").empty();
                for (var i = 0; i < obj.length; i++)
                {
                    $("#tds").append("<tr><td>" + obj[i].UserID + "</td><td>" + obj[i].UserTel + "</td><td>" + obj[i].UserPwd + "</td><td>" + obj[i].UserState + "</td><td>" + obj[i].UserRegTime + "</td><td><input type='button' value='停用'   class='btn btn-success'  onclick='Del(" + obj[i].UserID + ")'  /><input type='button' value='启用'   class='btn btn-success' onclick='Full(" + obj[i].UserID + ")' /></td></tr>");
                }
            }
        })
    })

    function Add() {
        var tel = $("#tel").val();
        var pass = $("#pass").val();
        var date = $("#date").val();

        if (tel.length == 11) {
            $.ajax({
                type: "post",
                url: "/Staff/StaffAdd",
                data: { UserTel: tel, UserPwd: pass, UserRegTime: date },
                success: function (obj) {
                    if (obj > 0) {
                        alert("添加成功,状态为停用");
                        location.href = '/Staff/StaffIndex';
                    }
                    else {
                        alert("失败!");
                    }
                }
            })
        }
        else {
            alert("手机号长度不正确");
        }
    }
    function Full(id) {
        $.ajax({
            type: "post",
            url: "/Staff/StaffFull",
            data: { UserID: id },

            success: function (obj) {
                if (obj > 0) {
                    alert("启用成功");
                    location.href = '/Staff/StaffIndex';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }
    function Del(id) {

        $.ajax({
            type: "post",
            url: "/Staff/StaffDel",
            data: { UserID: id },

            success: function (obj) {
                if (obj > 0) {
                    alert("停用成功");
                    location.href = '/Staff/StaffIndex';
                }
                else {
                    alert("失败!");
                }
            }
        })
    }
</script>
<input type="button" value="添加员工" class="btn btn-success" data-toggle="modal" data-target="#modal_add_user" />

<table class="table table-responsive">
    <tr>
        <td>编号</td>
        <td>姓名</td>
        <td>密码</td>
        <td>状态</td>
        <td>注册时间</td>
        <td>操作</td>
    </tr>
    <tbody id="tds">

    </tbody>
</table>

<div class="modal fade" id="modal_add_user" tabindex="-1" role="dialog" aria-labelledby="label_course">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="label_course"><strong>添加员工</strong></h4>
            </div>
            <div class="modal-body">
                <table class="table table-striped">
                    <tr><td>员工帐号</td><td><input type="text" id="tel" /></td></tr>
                    <tr><td>员工密码</td><td><input type="text" id="pass" /></td></tr>
                    <tr><td>注册时间</td><td><input type="date" id="date" /></td></tr>
                </table>
                <input type="button" value="添加" class="btn btn-success" onclick="Add()" />
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</div>